<?php
/**
 * Created by PhpStorm.
 * User: Edward
 * Date: 2019/6/4
 * Time: 13:50
 */

namespace app\admin\model;
use traits\model\SoftDelete;


class ShopGroup extends Base {
    use SoftDelete;
    /**
     * 通过名称查询分组是否存在
     * @param $name
     * @return array|\PDOStatement|string|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function findGroupByName($name){
       return self::field('group_name')->where([
           'group_name' => $name
       ])->where('delete_time','=',null)->find();
    }

    /**
     * 根据商家uid查询对应的分组
     * @param $uid
     * @return array|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function findGroupList($uid){
        return self::field('id,uid,group_name')->where([
            'uid' => $uid
        ])->select();
    }

    /**
     * 根据主键id查询对应的分组
     * @param $id
     * @return array|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function findGroupListById($id){
        return self::field('id,uid,group_name')->where('id','=',$id)
            ->where('delete_time','=',null)->select();
    }
}